<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    

    <title>杭州公共自行车app抓包分析 | 喵喵喵</title>
    <meta name="author" content="风之凌殇">
    
    <meta name="description" content="一个有趣的小世界~">
    
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <meta property="og:title" content="杭州公共自行车app抓包分析"/>
    <meta property="og:site_name" content="名字什么的最讨厌了呢"/>

    
    <meta property="og:image" content="undefined"/>
    

    <link rel="icon" type="image/png" href="/favicon.png">
    <link rel="alternate" href="/atom.xml" title="名字什么的最讨厌了呢" type="application/atom+xml">
    <link rel="stylesheet" href="/css/lib/materialize.min.css">
    <link rel="stylesheet" href="/css/lib/font-awesome.min.css">
    <link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">

    
        <link rel="stylesheet" href="/css/lib/prettify-tomorrow-night-eighties.css" type="text/css">
    
    <!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>


<body>
    <img src="/weixin_favicon.png" style="position: absolute; left: -9999px; opacity: 0; filter: alpha(opacity=0);">

    <nav class="green">
    <div class="nav-wrapper">
        <a href="#" data-activates="main-menu" class="button-collapse">
            <i class="fa fa-navicon"></i>
        </a>
        <div class="">
            <a href="/" class="brand-logo hide-on-med-and-down">名字什么的最讨厌了呢</a>
            <ul class="right hide-on-med-and-down">
                
                    <li>
                        <a class="menu-home " href="/" >
                            <i class="fa fa-home "></i>
                            
                            首页
                        </a>
                    </li>
                
                    <li>
                        <a class="menu-archive " href="/archives" >
                            <i class="fa fa-archive "></i>
                            
                            归档
                        </a>
                    </li>
                
                    <li>
                        <a class="menu-category category-menu" href="javascript:;" data-activates="category-menu" >
                            <i class="fa fa-bookmark "></i>
                            
                            分类
                        </a>
                    </li>
                
                    <li>
                        <a class="menu-reading " href="/reading" >
                            <i class="fa fa-book "></i>
                            
                            读书
                        </a>
                    </li>
                
                    <li>
                        <a class="menu-about " href="/about" >
                            <i class="fa fa-user "></i>
                            
                            关于
                        </a>
                    </li>
                
                    <li>
                        <a class="menu-search modal-trigger " href="#search" >
                            <i class="fa fa-search "></i>
                            
                            搜索
                        </a>
                    </li>
                
            </ul>
            <div>
    <ul class="side-nav green darken-1" id="main-menu">
        
        <li class="side-user">
            <div class="row">
                <div class="col s4 no-padding">
                    <img class="avatar-image circle responsive-img" src="/images/avatar.jpg" alt="User Avatar">
                </div>
                <div class="info col s8 valign-wrapper no-padding">
                    <div class="valign">
                        <p class="name">风之凌殇</p>
                        <p class="desc">Web后端/游戏/技术宅</p>
                    </div>
                </div>
            </div>
        </li>
        

        
            <li class="no-padding">
                <a class="waves-effect menu-home " href="/" >
                    <i class="fa fa-home "></i>
                    
                    首页
                </a>
            </li>
        
            <li class="no-padding">
                <a class="waves-effect menu-archive " href="/archives" >
                    <i class="fa fa-archive "></i>
                    
                    归档
                </a>
            </li>
        
            <li class="no-padding">
                <a class="waves-effect menu-category category-menu" href="javascript:;" data-activates="category-menu" >
                    <i class="fa fa-bookmark "></i>
                    
                    分类
                </a>
            </li>
        
            <li class="no-padding">
                <a class="waves-effect menu-reading " href="/reading" >
                    <i class="fa fa-book "></i>
                    
                    读书
                </a>
            </li>
        
            <li class="no-padding">
                <a class="waves-effect menu-about " href="/about" >
                    <i class="fa fa-user "></i>
                    
                    关于
                </a>
            </li>
        
            <li class="no-padding">
                <a class="waves-effect menu-search modal-trigger " href="#search" >
                    <i class="fa fa-search "></i>
                    
                    搜索
                </a>
            </li>
        
    </ul>

    <ul class="side-nav green darken-1" id="category-menu">
    

            

            <li class="collapse-level-0" collapse-level="0">
                <a class="no-padding" href="/categories/me/">
                    me <span class="right">1 篇</span></a>
                </a>
            </li>

        

            <li class="collapse-level-0" collapse-level="0">
                <a class="no-padding" href="/categories/miscellaneous/">
                    miscellaneous <span class="right">1 篇</span></a>
                </a>
            </li>

        

            <li class="collapse-level-0" collapse-level="0">
                <a class="no-padding" href="/categories/面试/">
                    面试 <span class="right">1 篇</span></a>
                </a>
            </li>

        

            <li class="collapse-level-0" collapse-level="0">
                <a class="no-padding" href="/categories/技术/">
                    技术 <span class="right">1 篇</span></a>
                </a>
            </li>

        

    </ul>
</div>

        </div>
    </div>
</nav>

<div id="search" class="modal search-modal">
    <div class="row">
        <div class="input-field col s12">
              <input id="search-input" type="text">
              <label for="search-input">搜索</label>
        </div>

    </div>
    <div id="search-result" class="search-result col s12">

    </div>
</div>


    <main>
        <div class="container main-container">
    <nav class="page-nav hide-on-small-only">
    <div class="nav-wrapper green">
        <span class="breadcrumb">当前位置（分类目录）</span>
        
            
    
    
    <a class="breadcrumb" href="/categories/技术/">技术</a>


        

        
    </div>
</nav>

<article>
    <div class="card">
        <div class="card-content">
            

            <div class="article-title">
                
    
        <h1>杭州公共自行车app抓包分析</h1>
    


            </div>
            <time class="red-link-context" datetime="2017-03-12T15:46:05.000Z"><a href="/技术/杭州公共自行车app抓包分析.html">2017-03-12</a></time>

            <span id="busuanzi_container_page_pv" class="read-times-container">
    <i class="fa fa-eye"></i>
    <span id="busuanzi_value_page_pv"></span>
</span>

            
    <div class="tags-row">
        
            <a href="/tags/抓包/" class="chip red lighten-1">抓包</a>
        
            <a href="/tags/爬虫/" class="chip red lighten-1">爬虫</a>
        
    </div>


            <div class="toc red-link-context hide-on-med-and-down">
    <ol class="section table-of-contents"><li class="section table-of-contents-item section table-of-contents-level-1"><a class="section table-of-contents-link" href="#安卓app"><span class="section table-of-contents-text">安卓app</span></a><ol class="section table-of-contents-child"><li class="section table-of-contents-item section table-of-contents-level-2"><a class="section table-of-contents-link" href="#抓包工具"><span class="section table-of-contents-text">抓包工具</span></a></li><li class="section table-of-contents-item section table-of-contents-level-2"><a class="section table-of-contents-link" href="#分析结果"><span class="section table-of-contents-text">分析结果</span></a></li></ol></li><li class="section table-of-contents-item section table-of-contents-level-1"><a class="section table-of-contents-link" href="#杭州公交车微信接口"><span class="section table-of-contents-text">杭州公交车微信接口</span></a><ol class="section table-of-contents-child"><li class="section table-of-contents-item section table-of-contents-level-2"><a class="section table-of-contents-link" href="#接口列表"><span class="section table-of-contents-text">接口列表</span></a></li><li class="section table-of-contents-item section table-of-contents-level-2"><a class="section table-of-contents-link" href="#微信版本获取数据"><span class="section table-of-contents-text">微信版本获取数据</span></a><ol class="section table-of-contents-child"><li class="section table-of-contents-item section table-of-contents-level-3"><a class="section table-of-contents-link" href="#Step-1-遍历公共自行车微信接口，并保存为json文件"><span class="section table-of-contents-text">Step 1. 遍历公共自行车微信接口，并保存为json文件</span></a></li><li class="section table-of-contents-item section table-of-contents-level-3"><a class="section table-of-contents-link" href="#Step-2-利用经纬度信息找到该车站，从而获取其信息"><span class="section table-of-contents-text">Step 2. 利用经纬度信息找到该车站，从而获取其信息</span></a></li></ol></li></ol></li><li class="section table-of-contents-item section table-of-contents-level-1"><a class="section table-of-contents-link" href="#一个简陋的前端"><span class="section table-of-contents-text">一个简陋的前端</span></a></li></ol>
</div>


            <div class="entry red-link-context">
                <p>去年实习时因个人需求需要获取历史的公共自行车各站点的车辆数目变化情况，但没有公开的数据接口，所以对其安卓app以及微信应用进行抓包分析，获取其数据接口，从而对历史的数据进行记录和分析。</p>
<a id="more"></a>
<h1 id="安卓app"><a href="#安卓app" class="headerlink" title="安卓app"></a>安卓app</h1><h2 id="抓包工具"><a href="#抓包工具" class="headerlink" title="抓包工具"></a>抓包工具</h2><ul>
<li>使用wireshark进行<ul>
<li>安卓wiresharek并启动</li>
<li>电脑开启虚拟WiFi</li>
<li>手机连接到该WiFi</li>
<li>手机端打开杭州公共自行车app</li>
<li>使用下列过滤表达式来选择我们需要的条目</li>
<li><code>(http.request.method== &quot;POST&quot; or http.request.method== &quot;GET&quot;) and ip.addr == 121.40.210.77</code></li>
</ul>
</li>
</ul>
<h2 id="分析结果"><a href="#分析结果" class="headerlink" title="分析结果"></a>分析结果</h2><ul>
<li><a href="http://bike.hz.dingdatech.com/service/version" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/version</a><ul>
<li>get</li>
<li>用于获取当前版本的app的一些相关信息的链接</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  <span class="attr">"meta"</span>: &#123;</div><div class="line">    <span class="attr">"code"</span>: <span class="number">200</span>,</div><div class="line">    <span class="attr">"message"</span>: <span class="string">"正常"</span></div><div class="line">  &#125;,</div><div class="line">  <span class="attr">"data"</span>: &#123;</div><div class="line">    <span class="attr">"version"</span>: &#123;&#125;,</div><div class="line">    <span class="attr">"basicInfo"</span>: &#123;</div><div class="line">      <span class="attr">"open_city_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/city.html"</span>,</div><div class="line">      <span class="attr">"index_problem_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/map_help.html"</span>,</div><div class="line">      <span class="attr">"contacts_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/contactUs.html"</span>,</div><div class="line">      <span class="attr">"about_us_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/about.html"</span>,</div><div class="line">      <span class="attr">"common_problem_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/question.html"</span>,</div><div class="line">      <span class="attr">"hire_problem_url"</span>: <span class="string">"http://wx.hz.dingdatech.com/hire_help.html"</span></div><div class="line">    &#125;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://push.hz.dingdatech.com/service/appclient" target="_blank" rel="external">http://push.hz.dingdatech.com/service/appclient</a><ul>
<li>post</li>
<li>token: e3412ab5f25XXXX….XXXXXXX</li>
<li>需要token，登陆后会随请求一起发送，从报文中copy下来即可</li>
</ul>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">r = requests.post(<span class="string">'http://push.hz.dingdatech.com/service/appclient'</span>,</div><div class="line">                  headers=&#123;</div><div class="line">                      <span class="string">'token'</span>: <span class="string">'07394d69b3682c448b3ae85713f9d8085585e9a671e8ffbb1510f056c38a2ba6'</span>,</div><div class="line">                      <span class="string">'source'</span>: <span class="string">'ANDROID'</span>,</div><div class="line">                  &#125;,</div><div class="line">                  data=&#123;</div><div class="line">                      <span class="string">'clientId'</span>: <span class="string">'909b9278b5d3b73c0675d29d1ac6ef1d'</span></div><div class="line">                  &#125;</div><div class="line">                  )</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/stations?latitude=30.299306&amp;longitude=120.118252" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/stations?latitude=30.299306&amp;longitude=120.118252</a><ul>
<li>get</li>
<li>用于获取该经纬度附近的车站信息</li>
</ul>
</li>
</ul>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  "meta": &#123;</div><div class="line">    "code": 200,</div><div class="line">    "message": "正常"</div><div class="line">  &#125;,</div><div class="line">  "data": &#123;</div><div class="line">    "stationLists": [</div><div class="line">      &#123;</div><div class="line">        "id": "20160802161027hzl01766",</div><div class="line">        "name": "西斗门",</div><div class="line">        "longitude": 120.121346,</div><div class="line">        "latitude": 30.29647,</div><div class="line">        "enHireNum": 0,//可租数目</div><div class="line">        "disHireNum": 0,//可还数目</div><div class="line">        "isSelected": true,</div><div class="line">        "type": 1</div><div class="line">      &#125;</div><div class="line">    ]</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/stations/20160802161027hzl01612" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/stations/20160802161027hzl01612</a><ul>
<li>get</li>
<li>最后一部分为车站的id，其中仅最后五位会发生变化，经测试发现有效范围为00002-03020，其中有大概二三十个id为无效的，可经测试剔除</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">    <span class="attr">"meta"</span>: &#123;</div><div class="line">        <span class="attr">"code"</span>: <span class="number">200</span>,</div><div class="line">        <span class="attr">"message"</span>: <span class="string">"正常"</span></div><div class="line">        &#125;,</div><div class="line">    <span class="attr">"data"</span>: &#123;</div><div class="line">        <span class="attr">"station"</span>: &#123;</div><div class="line">            <span class="attr">"id"</span>: <span class="string">"20160802161027hzl01612"</span>,</div><div class="line">            <span class="attr">"name"</span>: <span class="string">"萍水东路塘中路口西南角"</span>,</div><div class="line">            <span class="attr">"longitude"</span>: <span class="number">120.114674</span>,</div><div class="line">            <span class="attr">"latitude"</span>: <span class="number">30.306814</span>,</div><div class="line">            <span class="attr">"enHireNum"</span>: <span class="number">0</span>,</div><div class="line">            <span class="attr">"disHireNum"</span>: <span class="number">0</span>,</div><div class="line">            <span class="attr">"isSelected"</span>: <span class="literal">true</span>,</div><div class="line">            <span class="attr">"type"</span>: <span class="number">0</span></div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/deposit?latitude=30.299304&amp;longitude=120.118252" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/deposit?latitude=30.299304&amp;longitude=120.118252</a><ul>
<li>get</li>
<li>需要登陆后获得的token</li>
<li>扫码租车系统</li>
<li>正常登陆结果</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&#123;<span class="attr">"meta"</span>:&#123;<span class="attr">"code"</span>:<span class="number">200</span>,<span class="attr">"message"</span>:<span class="string">"正常"</span>&#125;,<span class="attr">"data"</span>:&#123;<span class="attr">"toPaid"</span>:<span class="number">500.0</span>,<span class="attr">"isActive"</span>:<span class="literal">false</span>&#125;&#125;</div></pre></td></tr></table></figure>
<pre><code>- 未登录结果
</code></pre><figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  <span class="attr">"meta"</span>: &#123;</div><div class="line">    <span class="attr">"code"</span>: <span class="number">401</span>,</div><div class="line">    <span class="attr">"message"</span>: <span class="string">"未授权"</span></div><div class="line">  &#125;,</div><div class="line">  <span class="attr">"data"</span>: &#123;</div><div class="line">    <span class="attr">"error"</span>: <span class="string">"错误的token[07394d69b3682c448b3ae85713f9d8085585e9a671e8ffbb1510f056c38a2ba6]"</span></div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/orders/unfinished" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/orders/unfinished</a><ul>
<li>get</li>
<li>需要token</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&#123;<span class="attr">"meta"</span>:&#123;<span class="attr">"code"</span>:<span class="number">200</span>,<span class="attr">"message"</span>:<span class="string">"正常"</span>&#125;,<span class="attr">"data"</span>:&#123;<span class="attr">"unfinishedOrder"</span>:&#123;&#125;&#125;&#125;</div></pre></td></tr></table></figure>
<ul>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/orders?pageNum=1&amp;pageSize=20" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/orders?pageNum=1&amp;pageSize=20</a><ul>
<li>get</li>
<li>需要token</li>
<li>参数<ul>
<li>pageNum</li>
<li>pageSize</li>
</ul>
</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&#123;<span class="attr">"meta"</span>:&#123;<span class="attr">"code"</span>:<span class="number">200</span>,<span class="attr">"message"</span>:<span class="string">"正常"</span>&#125;,<span class="attr">"data"</span>:&#123;<span class="attr">"orders"</span>:[]&#125;&#125;</div></pre></td></tr></table></figure>
<blockquote>
<p>由于新版本更新，应用整体架构发生变化，似乎启用了HTTPS，旧的一些接口已被弃用，所以目前改用微信版本的接口获取数据</p>
</blockquote>
<h1 id="杭州公交车微信接口"><a href="#杭州公交车微信接口" class="headerlink" title="杭州公交车微信接口"></a>杭州公交车微信接口</h1><h2 id="接口列表"><a href="#接口列表" class="headerlink" title="接口列表"></a>接口列表</h2><ul>
<li><a href="http://c.ggzxc.com.cn/wz/np_getBikesByWeiXin.do?lng=120.107&amp;lat=30.295301&amp;len=800&amp;_=1472267874845" target="_blank" rel="external">http://c.ggzxc.com.cn/wz/np_getBikesByWeiXin.do?lng=120.107&amp;lat=30.295301&amp;len=800&amp;_=1472267874845</a><ul>
<li>get</li>
<li>根据经纬度及搜索半径获取车站列表</li>
<li>params:<ul>
<li>lng: 经度</li>
<li>lat: 纬度</li>
<li>len: 仅距离所设点距离不超过len的车站会被列出</li>
<li>_: 请求发送时的时间戳，可不加</li>
</ul>
</li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  <span class="attr">"count"</span>: <span class="number">10</span>,</div><div class="line">  <span class="attr">"data"</span>: [</div><div class="line">    &#123;</div><div class="line">      <span class="attr">"address"</span>: <span class="string">"西斗门20号旁电力配电房南侧人行道"</span>,</div><div class="line">      <span class="attr">"areaname"</span>: <span class="string">"城西"</span>,</div><div class="line">      <span class="attr">"bikenum"</span>: <span class="string">"24"</span>,</div><div class="line">      <span class="attr">"createTime"</span>: <span class="number">1472268848395</span>,</div><div class="line">      <span class="attr">"guardType"</span>: <span class="string">"无人值守"</span>,</div><div class="line">      <span class="attr">"id"</span>: <span class="number">22956</span>,</div><div class="line">      <span class="attr">"lat"</span>: <span class="string">"30.29647"</span>,</div><div class="line">      <span class="attr">"len"</span>: <span class="string">"439"</span>,</div><div class="line">      <span class="attr">"lon"</span>: <span class="string">"120.121346"</span>,</div><div class="line">      <span class="attr">"name"</span>: <span class="string">"西斗门"</span>,</div><div class="line">      <span class="attr">"number"</span>: <span class="string">"5054"</span>,</div><div class="line">      <span class="attr">"rentcount"</span>: <span class="string">"2"</span>,</div><div class="line">      <span class="attr">"restorecount"</span>: <span class="string">"23"</span>,</div><div class="line">      <span class="attr">"serviceType"</span>: <span class="string">"06:00-24:00"</span>,</div><div class="line">      <span class="attr">"sort"</span>: <span class="number">0</span>,</div><div class="line">      <span class="attr">"stationPhone"</span>: <span class="string">"(7:00-21:30)|15868118476"</span>,</div><div class="line">      <span class="attr">"stationPhone2"</span>: <span class="string">"(21:30-24:00)|15258861473"</span>,</div><div class="line">      <span class="attr">"useflag"</span>: <span class="string">"正常"</span></div><div class="line">    &#125;</div><div class="line">    ]</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<blockquote>
<p>该接口所使用的坐标系加密方式与安卓版本似乎有所不同，同一车站对应的坐标有所差异，估计是双方使用的地图api提供商不同（如百度或腾讯地图等）</p>
</blockquote>
<ul>
<li><p><a href="http://c.ggzxc.com.cn/wz/np_findNetPointByName.do" target="_blank" rel="external">http://c.ggzxc.com.cn/wz/np_findNetPointByName.do</a></p>
<ul>
<li>根据关键字搜索站点</li>
<li>params:<ul>
<li>option: 全文索引的关键词</li>
</ul>
</li>
</ul>
</li>
<li><p><a href="http://c.ggzxc.com.cn/wz/np_getBikes.do?lng=120.125524&amp;lat=30.332081&amp;len=800&amp;_=1472272269109" target="_blank" rel="external">http://c.ggzxc.com.cn/wz/np_getBikes.do?lng=120.125524&amp;lat=30.332081&amp;len=800&amp;_=1472272269109</a></p>
<ul>
<li>get</li>
<li>与之前的接口使用的坐标系有所不同</li>
<li>搜索得出的结果中的坐标系与该接口是一致的</li>
<li>参数与之前的接口一样</li>
</ul>
</li>
</ul>
<h2 id="微信版本获取数据"><a href="#微信版本获取数据" class="headerlink" title="微信版本获取数据"></a>微信版本获取数据</h2><p>由于之前的安卓部分关键接口不可用，所以考虑通过微信版本的接口进行获取数据，但是由于其接口没有明显的可遍历的方式，因此需要做一些额外的工作</p>
<h3 id="Step-1-遍历公共自行车微信接口，并保存为json文件"><a href="#Step-1-遍历公共自行车微信接口，并保存为json文件" class="headerlink" title="Step 1. 遍历公共自行车微信接口，并保存为json文件"></a>Step 1. 遍历公共自行车微信接口，并保存为json文件</h3><ul>
<li>利用安卓旧版接口<ul>
<li>let stations = []</li>
<li><a href="http://bike.hz.dingdatech.com/service/bicycle/stations/20160802161027hzl00556" target="_blank" rel="external">http://bike.hz.dingdatech.com/service/bicycle/stations/20160802161027hzl00556</a></li>
<li>根据上方接口末尾的最后五位{id}从00002遍历到03140，得到对应的车站的信息</li>
<li>从上述信息中提取经纬度信息</li>
<li>将该车站站名，经度，纬度信息放入结果数组中</li>
<li>完成遍历</li>
<li>将结果数组保存到json文件中</li>
</ul>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> json</div><div class="line"></div><div class="line"><span class="keyword">import</span> requests</div><div class="line"></div><div class="line">base_url = <span class="string">'http://bike.hz.dingdatech.com/service/bicycle/stations/20160802161027hzl%05d'</span></div><div class="line"></div><div class="line">stations = []</div><div class="line"><span class="keyword">for</span> station_id <span class="keyword">in</span> range(<span class="number">2</span>, <span class="number">3021</span>):</div><div class="line">    res = requests.get(base_url % station_id).json()</div><div class="line"></div><div class="line">    <span class="keyword">if</span> res[<span class="string">'meta'</span>][<span class="string">'code'</span>] != <span class="number">200</span>:</div><div class="line">        print(station_id, res[<span class="string">'meta'</span>][<span class="string">'message'</span>])</div><div class="line">        <span class="keyword">continue</span></div><div class="line"></div><div class="line">    stations.append(res[<span class="string">'data'</span>][<span class="string">'station'</span>])</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'bicycle_stations_list_from_android.json'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> save:</div><div class="line">    json.dump(stations, save, indent=<span class="number">4</span>)</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'bicycle_stations_list_from_android_not_ascii.json'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> save:</div><div class="line">    json.dump(stations, save, ensure_ascii=<span class="keyword">False</span>, indent=<span class="number">4</span>)</div></pre></td></tr></table></figure>
<blockquote>
<p>经测试发现这种方法得到的部分站点（二三十个）的经纬度与微信版本的获取数据的接口不相容</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># 为了解决这个问题，尝试第不相容的数据通过微信的搜索站点接口查找对应的坐标</span></div><div class="line"><span class="keyword">import</span> json</div><div class="line"></div><div class="line"><span class="keyword">import</span> requests</div><div class="line"></div><div class="line">base_url = <span class="string">'http://c.ggzxc.com.cn/wz/np_getBikes.do'</span></div><div class="line">find_by_name_url = <span class="string">'http://c.ggzxc.com.cn/wz/np_findNetPointByName.do'</span></div><div class="line"></div><div class="line">validated_stations = []</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'bicycle_stations_list_from_android_not_ascii.json'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> data:</div><div class="line">    stations = json.load(data)</div><div class="line"></div><div class="line">    <span class="keyword">for</span> station <span class="keyword">in</span> stations:</div><div class="line">        name = station[<span class="string">'name'</span>]</div><div class="line">        lng = station[<span class="string">'longitude'</span>]</div><div class="line">        lat = station[<span class="string">'latitude'</span>]</div><div class="line"></div><div class="line">        res = requests.get(base_url, &#123;</div><div class="line">            <span class="string">'lng'</span>: lng,</div><div class="line">            <span class="string">'lat'</span>: lat,</div><div class="line">            <span class="string">'len'</span>: <span class="number">0</span></div><div class="line">        &#125;).json()</div><div class="line"></div><div class="line">        <span class="keyword">if</span> res[<span class="string">'count'</span>] == <span class="number">0</span>:</div><div class="line">            <span class="comment"># if not found, use the name as the option value for the following api to try if can get new lat and lon</span></div><div class="line">            <span class="comment"># http://c.ggzxc.com.cn/wz/np_findNetPointByName.do?option=%E5%9F%8E%E8%A5%BF</span></div><div class="line">            res = requests.get(find_by_name_url, &#123;</div><div class="line">                <span class="string">'option'</span>: name</div><div class="line">            &#125;).json()</div><div class="line"></div><div class="line">            <span class="keyword">if</span> len(res[<span class="string">'data'</span>]) == <span class="number">0</span>:</div><div class="line">                print(<span class="string">'\n%s not found'</span> % name)</div><div class="line">            <span class="keyword">else</span>:</div><div class="line">                _station = res[<span class="string">'data'</span>][<span class="number">0</span>][<span class="string">'result'</span>]</div><div class="line">                validated_stations.append(&#123;</div><div class="line">                    <span class="string">'name'</span>: _station[<span class="string">'name'</span>],</div><div class="line">                    <span class="string">'lng'</span>: _station[<span class="string">'lon'</span>],</div><div class="line">                    <span class="string">'lat'</span>: _station[<span class="string">'lat'</span>]</div><div class="line">                &#125;)</div><div class="line">                print(<span class="string">'.'</span>, end=<span class="string">''</span>, flush=<span class="keyword">True</span>)</div><div class="line">        <span class="keyword">else</span>:</div><div class="line">            validated_stations.append(&#123;</div><div class="line">                <span class="string">'name'</span>: station[<span class="string">'name'</span>],</div><div class="line">                <span class="string">'lng'</span>: station[<span class="string">'longitude'</span>],</div><div class="line">                <span class="string">'lat'</span>: station[<span class="string">'latitude'</span>]</div><div class="line">            &#125;)</div><div class="line">            print(<span class="string">'.'</span>, end=<span class="string">''</span>, flush=<span class="keyword">True</span>)</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'__test.json'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> debug:</div><div class="line">    json.dump(validated_stations, debug, ensure_ascii=<span class="keyword">False</span>, indent=<span class="number">4</span>)</div><div class="line"></div><div class="line"><span class="comment"># total number is 2970 sites</span></div><div class="line"></div><div class="line"><span class="comment"># with open('__test.json', 'r', encoding='utf-8') as debug:</span></div><div class="line"><span class="comment">#     validated_stations = json.load(debug)</span></div><div class="line"><span class="comment">#     print(len(validated_stations))</span></div></pre></td></tr></table></figure>
<blockquote>
<p>尽管做了一些修复，但仍有部分站点有问题，所以考虑通过微信自己的接口进行搜索遍历</p>
</blockquote>
<ul>
<li>利用微信搜索接口<ul>
<li><a href="http://c.ggzxc.com.cn/wz/np_findNetPointByName.do?option=1001" target="_blank" rel="external">http://c.ggzxc.com.cn/wz/np_findNetPointByName.do?option=1001</a></li>
</ul>
</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line"><span class="attr">"data"</span>: [</div><div class="line">    &#123;</div><div class="line">    <span class="attr">"result"</span>: &#123;</div><div class="line">            <span class="attr">"address"</span>: <span class="string">"延安路明珠小百货门前"</span>,</div><div class="line">            <span class="attr">"areaname"</span>: <span class="string">"城南"</span>,</div><div class="line">            <span class="attr">"bikenum"</span>: <span class="string">"21"</span>,</div><div class="line">            <span class="attr">"createTime"</span>: <span class="number">1438511647000</span>,</div><div class="line">            <span class="attr">"guardType"</span>: <span class="string">"无人值守"</span>,</div><div class="line">            <span class="attr">"id"</span>: <span class="number">23329</span>,</div><div class="line">            <span class="attr">"isDeleted"</span>: <span class="literal">false</span>,</div><div class="line">            <span class="attr">"lat"</span>: <span class="string">"30.263758"</span>,</div><div class="line">            <span class="attr">"lon"</span>: <span class="string">"120.170667"</span>,</div><div class="line">            <span class="attr">"name"</span>: <span class="string">"明珠商业中心"</span>,</div><div class="line">            <span class="attr">"number"</span>: <span class="string">"1011"</span>,</div><div class="line">            <span class="attr">"serviceType"</span>: <span class="string">"06:00-24:00"</span>,</div><div class="line">            <span class="attr">"sort"</span>: <span class="number">0</span>,</div><div class="line">            <span class="attr">"stationPhone"</span>: <span class="string">"(7:00-19:00)|13606524069"</span>,</div><div class="line">            <span class="attr">"stationPhone2"</span>: <span class="string">"(19:00-24:00)|13606519453"</span>,</div><div class="line">            <span class="attr">"useflag"</span>: <span class="string">"正常"</span></div><div class="line">        &#125;,</div><div class="line">    <span class="attr">"title"</span>: <span class="string">"明珠商业中心 - 1011"</span></div><div class="line">    &#125;</div><div class="line">]</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>- 通过选择合适的option（即搜索关键词）遍历方式来遍历得到站点
    + 乍看之下id似乎可以较好地进行遍历，但是由于未能发现通过id进行查找站点当前状态的接口，最终放弃该方案
    + 经过尝试发现，站点的number属性似乎可以作为一个不错的唯一识别码，而且其具有较明显的构造规律，经测试发现该属性从1001开始有效，经过随机探测发现10000以内的多个区域均有效，最终决定将探测上限设为15000，进行线性探测，并将结果保存到json文件中
</code></pre><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># 利用微信接口获取较为完整的站点以及坐标信息列表</span></div><div class="line"><span class="keyword">import</span> json</div><div class="line"><span class="keyword">import</span> requests</div><div class="line"></div><div class="line">base_url = <span class="string">'http://c.ggzxc.com.cn/wz/np_findNetPointByName.do'</span></div><div class="line"></div><div class="line">n_true = <span class="number">0</span></div><div class="line">n_false = <span class="number">0</span></div><div class="line">n_none = <span class="number">0</span></div><div class="line"></div><div class="line">stations = []</div><div class="line"></div><div class="line"><span class="keyword">for</span> number <span class="keyword">in</span> range(<span class="number">1001</span>, <span class="number">15000</span>):</div><div class="line">    print(<span class="string">'\rstart check %05d'</span> % number, end=<span class="string">''</span>)</div><div class="line"></div><div class="line">    <span class="keyword">while</span> <span class="keyword">True</span>:</div><div class="line">        <span class="keyword">try</span>:</div><div class="line">            res = requests.get(base_url, params=&#123;</div><div class="line">                <span class="string">'option'</span>: number</div><div class="line">            &#125;)</div><div class="line">            <span class="keyword">break</span></div><div class="line">        <span class="keyword">except</span> TimeoutError:</div><div class="line">            print(<span class="string">'sleep for a 10 seconds'</span>)</div><div class="line">            time.sleep(<span class="number">10</span>)</div><div class="line"></div><div class="line">    data = res.json()[<span class="string">'data'</span>]</div><div class="line">    <span class="keyword">if</span> len(data) == <span class="number">0</span>:</div><div class="line">        n_none += <span class="number">1</span></div><div class="line">        <span class="comment"># print('none', number)</span></div><div class="line">        <span class="keyword">continue</span></div><div class="line"></div><div class="line">    res_number = data[<span class="number">0</span>][<span class="string">'result'</span>][<span class="string">'number'</span>]</div><div class="line">    <span class="keyword">if</span> res_number == str(number):</div><div class="line">        n_true += <span class="number">1</span></div><div class="line">        stations.append(data[<span class="number">0</span>])</div><div class="line">        <span class="comment"># print("true", number)</span></div><div class="line">    <span class="keyword">else</span>:</div><div class="line">        n_false += <span class="number">1</span></div><div class="line">        <span class="comment"># print("false", number)</span></div><div class="line"></div><div class="line">print(<span class="string">'total number of stations : %d'</span> % (n_true))</div><div class="line">print(<span class="string">'false : %d'</span> % (n_false))</div><div class="line">print(<span class="string">'none  : %d'</span> % (n_none))</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'bicycle_stations_list_from_wechat.json'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> save:</div><div class="line">    json.dump(stations, save, indent=<span class="number">4</span>)</div><div class="line"></div><div class="line"><span class="keyword">with</span> open(<span class="string">'bicycle_stations_list_from_wechat_not_ascii.json'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> save:</div><div class="line">    json.dump(stations, save, ensure_ascii=<span class="keyword">False</span>, indent=<span class="number">4</span>)</div></pre></td></tr></table></figure>
<blockquote>
<p>由于微信接口中的number（即其唯一识别码）并不像安卓版本那样0-3020顺序分布，而是中间有很多的空洞，比如1020开始有一段几百的空洞，此外通过试探可以发现1001,5999，10001等多个不同区间内均有效，所以探测完整的区间需要大量时间，而且很有可能有所疏漏。</p>
</blockquote>
<h3 id="Step-2-利用经纬度信息找到该车站，从而获取其信息"><a href="#Step-2-利用经纬度信息找到该车站，从而获取其信息" class="headerlink" title="Step 2. 利用经纬度信息找到该车站，从而获取其信息"></a>Step 2. 利用经纬度信息找到该车站，从而获取其信息</h3><ol>
<li>读取之前获取的站点坐标信息</li>
<li>调用<a href="http://c.ggzxc.com.cn/wz/np_getBikes.do?lng=120.19555&amp;lat=30.344349&amp;len=800&amp;_=1472272269109接口获取每一个经纬度附近的车站，其中第一个即为我们所需要的车站，从其中解析我们需要的数据存储到数据库中即可" target="_blank" rel="external">http://c.ggzxc.com.cn/wz/np_getBikes.do?lng=120.19555&amp;lat=30.344349&amp;len=800&amp;_=1472272269109接口获取每一个经纬度附近的车站，其中第一个即为我们所需要的车站，从其中解析我们需要的数据存储到数据库中即可</a></li>
</ol>
<h1 id="一个简陋的前端"><a href="#一个简陋的前端" class="headerlink" title="一个简陋的前端"></a>一个简陋的前端</h1><ul>
<li>针对选定的站点，展示其历史变化信息<ul>
<li><a href="http://bicycle.chenji-meow.cn" target="_blank" rel="external">http://bicycle.chenji-meow.cn</a></li>
</ul>
</li>
<li>源代码<ul>
<li><a href="https://github.com/fzls/bicycle" target="_blank" rel="external">https://github.com/fzls/bicycle</a></li>
</ul>
</li>
</ul>

                
<p class="red-link-context">
    <a href="/面试/酷家乐面试.html" rel="next" title="酷家乐面试">
    上一篇：酷家乐面试
  </a>
</p>



<p class="red-link-context">
    <a href="/miscellaneous/TODO.html" rel="next" title="TODOs of this blog">
    下一篇：TODOs of this blog
  </a>
</p>


            </div>
			
        </div>
    </div>
</article>




    <section id="comment">
        <div class="card">
            <div class="card-content">
                <!-- Duoshuo Comment BEGIN -->
                <div class="ds-thread" data-thread-key="技术/杭州公共自行车app抓包分析.html" data-title="杭州公共自行车app抓包分析" data-url="https://fzls.github.io/技术/杭州公共自行车app抓包分析.html"></div>

                <script type="text/javascript">
                    console.log(document.querySelector('.ds-thread'));
                    var duoshuoQuery = {
                        short_name: 'fzls'
                    };
                    (function() {
                        var ds = document.createElement('script');
                        ds.type = 'text/javascript';
                        ds.async = true;
                        ds.src = (document.location.protocol == 'https:'
                            ? 'https:'
                            : 'http:') + '//static.duoshuo.com/embed.js';
                        ds.charset = 'UTF-8';
                        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds);
                    })();
                </script>
                <!-- Duoshuo Comment END -->
            </div>
        </div>
    </section>



</div>

        <div class="fixed-action-btn float-sitemap">
    <a class="btn-floating btn-large red">
      <i class="fa fa-caret-square-o-up"></i>
    </a>
    <ul>
      <li><a class="btn-return-top btn-floating waves-effect cyan" title="回到顶部"><i class="fa fa-arrow-circle-o-up"></i></a></li>
      <li><a class="btn-floating waves-effect button-collapse light-green"  data-activates="main-menu" title="menu"><i class="fa fa-navicon"></i></a></li>
    </ul>
  </div>

    </main>
    <footer class="page-footer green darken-1">
    
    <div class="container">
        <div class="row">
            
            <div class="social-group col m4 s12">
                <h5 class="white-text">社交</h5>
                
                    <a class="social-link" href="https://github.com/fzls" target="_blank">
                        <i class="fa fa-2x fa-github"></i>
                    </a>
                
                    <a class="social-link" href="/atom.xml" target="_blank">
                        <i class="fa fa-2x fa-rss"></i>
                    </a>
                
                <div class="site-visitors-container white-text">
                    <span>
                        <i class="fa fa-user"></i>
                        <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
                    </span>
                    <span>&nbsp;|&nbsp;</span>
                    <span>
                        <i class="fa fa-eye"></i>
                        <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
                    </span>
                </div>
            </div>
            

            
            <div class="col m8 s12">
                <h5 class="white-text">友情链接</h5>
                
            </div>
            
        </div>
    </div>
    

    <div class="footer-copyright red-link-context">
        <div class="container">
            © 2017 风之凌殇, All rights reserved.
            <p class="right" style="margin-top: 0;">本博客由 <a href="https://hexo.io">Hexo</a> 强力驱动 | 主题 <a href="https://github.com/raytaylorlin/hexo-theme-raytaylorism">raytaylorism</a></p>
        </div>
    </div>
</footer>


    <noscript>
    <div class="noscript">
        <p class="center-align">当前网速较慢或者你使用的浏览器不支持博客特定功能，请尝试刷新或换用Chrome、Firefox等现代浏览器</p>
    </div>
</noscript>
<div class="noscript">
    <p class="center-align">当前网速较慢或者你使用的浏览器不支持博客特定功能，请尝试刷新或换用Chrome、Firefox等现代浏览器</p>
</div>


<script src="/js/jquery.min.js"></script>
<script src="/js/materialize.min.js"></script>
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<script>
    (function($) {
        $(document).ready(function() {
            // 隐藏禁用javascript（针对微信内置浏览器）的提示
            $('.noscript').hide();

            // 图片缩放效果
            var $imgs = $('img').not('.slider-image').not('.avatar-image').not('.carousel-image').not('.card-cover-image').not('.qrcode');

            // 给图片加上点击放大效果（materialbox插件）
            $imgs.addClass('materialboxed').each(function(i, el) {
                $(this).attr('data-caption', $(this).attr('alt') || ' ');
            }).materialbox();

            // 优化表格的显示
            $('table').each(function() {
                var $table = $(this);
                // 除去多行代码的情况
                if ($table.find('pre').length == 0) {
                    $table.addClass('responsive-table striped bordered');
                }
            });

            // 首页幻灯片
            $('.slider').slider({indicators: true, full_width: true, interval: 8000});

            $(".button-collapse").sideNav();
            $(".category-menu").sideNav();

            // 针对gallery post
            $('.carousel').carousel({full_width: true});
            $('.carousel-control.prev').click(function() {
                $('.carousel').carousel('prev');
            });
            $('.carousel-control.next').click(function() {
                $('.carousel').carousel('next');
            });

            // 文章目录
            $('article').not('.simple-article').find('h1').add('h2').add('h3').add('h4').add('h5').add('h6').scrollSpy();

            // 目录随屏幕滚动（防止目录过长越过footer）
            var $toc = $('.toc');
            var scrollTargetTop = 0;
            $(window).scroll(function() {
                var $activeLink = $toc.find('a.active.section');
                if ($(window).scrollTop() < 100) {
                    scrollTargetTop = 0;
                } else {
                    if ($activeLink[0]) {
                        scrollTargetTop = $activeLink.offset().top - $toc.offset().top;
                    }
                }
                $toc.css('top', '-' + scrollTargetTop + 'px');
            });

            // 修正文章目录的left-border颜色
            var color = $('.table-of-contents-text').css('color');
            $('.table-of-contents-link').css('border-left-color', color);

            // 针对移动端做的优化：FAB按钮点击一下收回
            if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
                $('.fixed-action-btn').addClass('click-to-toggle');
            }
            // 回到顶部
            $('.btn-return-top').click(function() {
                $('body, html').animate({
                    scrollTop: 0
                }, 500);
            });

            // 重置读书页面的Tab标签页的颜色
            $('li.tab a').hover(function() {
                $(this).toggleClass('text-lighten-4');
            });
            $('.indicator').addClass('red lighten-2');

            
            // 添加new标签
            $('').append('<span class="new badge red"></span>');
            

            // 搜索功能
            $('.modal-trigger').leanModal({
                // 打开搜索框时自动聚焦
                ready: function() {
                    if ($('#search').is(":visible")) {
                        $('#search-input').focus();
                    }
                }
            });
            var searchXml = "search.xml";
            if (searchXml.length == 0) {
             	searchXml = "search.xml";
            }
            var searchPath = "/" + searchXml;
            initSearch(searchPath, 'search-input', 'search-result');
        });

        // 初始化搜索与匹配函数
        var initSearch = function(path, search_id, content_id) {
            'use strict';
            $.ajax({
                url: path,
                dataType: "xml",
                success: function(xmlResponse) {
                    // get the contents from search data
                    var datas = $("entry", xmlResponse).map(function() {
                        return {
                            title: $("title", this).text(),
                            content: $("content", this).text(),
                            url: $("url", this).text()
                        };
                    }).get();
                    var $input = document.getElementById(search_id);
                    var $resultContent = document.getElementById(content_id);
                    $input.addEventListener('input', function() {
                        var str = '<ul class=\"search-result-list\">';
                        var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                        $resultContent.innerHTML = "";
                        if (this.value.trim().length <= 0) {
                            return;
                        }
                        // perform local searching
                        datas.forEach(function(data) {
                            var isMatch = true;
                            var content_index = [];
                            var data_title = data.title.trim().toLowerCase();
                            var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                            var data_url = data.url;
                            var index_title = -1;
                            var index_content = -1;
                            var first_occur = -1;
                            // only match artiles with not empty titles and contents
                            if (data_title != '' && data_content != '') {
                                keywords.forEach(function(keyword, i) {
                                    index_title = data_title.indexOf(keyword);
                                    index_content = data_content.indexOf(keyword);
                                    if (index_title < 0 && index_content < 0) {
                                        isMatch = false;
                                    } else {
                                        if (index_content < 0) {
                                            index_content = 0;
                                        }
                                        if (i == 0) {
                                            first_occur = index_content;
                                        }
                                    }
                                });
                            }
                            // show search results
                            if (isMatch) {
                                keywords.forEach(function(keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    data_title = data_title.replace(regS, "<span class=\"search-keyword red lighten-2\">" + keyword + "</span>");
                                });

                                str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                                var content = data.content.trim().replace(/<[^>]+>/g, "");
                                if (first_occur >= 0) {
                                    // cut out 100 characters
                                    var start = first_occur - 20;
                                    var end = first_occur + 80;
                                    if (start < 0) {
                                        start = 0;
                                    }
                                    if (start == 0) {
                                        end = 100;
                                    }
                                    if (end > content.length) {
                                        end = content.length;
                                    }
                                    var match_content = content.substring(start, end);
                                    // highlight all keywords
                                    keywords.forEach(function(keyword) {
                                        var regS = new RegExp(keyword, "gi");
                                        match_content = match_content.replace(regS, "<span class=\"search-keyword red lighten-2\">" + keyword + "</span>");
                                    });

                                    str += "<p class=\"search-result\">..." + match_content + "...</p>"
                                }
                                str += "</li>";
                            }
                        });
                        str += "</ul>";
                        $resultContent.innerHTML = str;
                    });
                }
            });
        }
    })(jQuery);
</script>


<script src="/js/prettify.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("pre").addClass("prettyprint");
        prettyPrint();
    });
</script>


<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-85758851-2', 'auto');
    ga('send', 'pageview');

</script>





<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" async
  src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>



</body>
</html>
